#include "common.h"

char prv(char c)
{
	if (c == 'c') return 'k';
	if (c == 'r') return 'c';
	if (c == 'o') return 'r';
	if (c == 'a') return 'o';
	if (c == 'k') return 'a';
	return ' ';
}
int minNumberOfFrogs(string croakOfFrogs)
{
	int num = 0;
	unordered_map<char, int> mp;
	for (int i = 0; i < croakOfFrogs.size(); i++)
	{
		char tar = prv(croakOfFrogs[i]);
		int j = 0;
		if (mp[tar] > 0)
		{
			mp[tar]--;
			mp[croakOfFrogs[i]]++;
		}
		else
		{
			if (croakOfFrogs[i] != 'c') return -1;
			mp['c']++;
			num++;
		}
	}
	for (auto& it : mp)
	{
		if (it.first != 'k' && it.second != 0) return -1;
	}
	return num;
}
